package cn.stylefeng.guns.modular.opportunities.controller;

import cn.stylefeng.roses.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import cn.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import cn.stylefeng.guns.modular.system.model.Bopportunities;
import cn.stylefeng.guns.modular.opportunities.service.IBopportunitiesService;

/**
 * 商机管理控制器
 *
 * @author fengshuonan
 * @Date 2018-08-14 22:17:45
 */
@Controller
@RequestMapping("/bopportunities")
public class BopportunitiesController extends BaseController {

    private String PREFIX = "/opportunities/bopportunities/";

    @Autowired
    private IBopportunitiesService bopportunitiesService;

    /**
     * 跳转到商机管理首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "bopportunities.html";
    }

    /**
     * 跳转到添加商机管理
     */
    @RequestMapping("/bopportunities_add")
    public String bopportunitiesAdd() {
        return PREFIX + "bopportunities_add.html";
    }

    /**
     * 跳转到修改商机管理
     */
    @RequestMapping("/bopportunities_update/{bopportunitiesId}")
    public String bopportunitiesUpdate(@PathVariable Integer bopportunitiesId, Model model) {
        Bopportunities bopportunities = bopportunitiesService.selectById(bopportunitiesId);
        model.addAttribute("item",bopportunities);
        LogObjectHolder.me().set(bopportunities);
        return PREFIX + "bopportunities_edit.html";
    }
    /**
     * 详细信息
     */
    @RequestMapping("/bopportunities_detail/{bopportunitiesId}")
    public String bopportunitiesDetails(@PathVariable Integer bopportunitiesId, Model model) {
        Bopportunities bopportunities = bopportunitiesService.selectById(bopportunitiesId);
        model.addAttribute("item",bopportunities);
        LogObjectHolder.me().set(bopportunities);
        return PREFIX + "bopportunities_detail.html";
    }
    /**
     * 上一页
     */
    @RequestMapping("/bopportunities_detail_next/{bopportunitiesId}")
    public String bopportunitiesDetailsNext(@PathVariable Integer bopportunitiesId, Model model) {
        Bopportunities bopportunities = bopportunitiesService.fandOneNext(bopportunitiesId);
        model.addAttribute("item",bopportunities);
        LogObjectHolder.me().set(bopportunities);
        return PREFIX + "bopportunities_detail.html";
    }
    /**
     * 下一页
     */
    @RequestMapping("/bopportunities_detail_last/{bopportunitiesId}")
    public String bopportunitiesDetailsLast(@PathVariable Integer bopportunitiesId, Model model) {
        Bopportunities bopportunities = bopportunitiesService.fandOneLast(bopportunitiesId);
        model.addAttribute("item",bopportunities);
        LogObjectHolder.me().set(bopportunities);
        return PREFIX + "bopportunities_detail.html";
    }

    /**
     * 获取商机管理列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return bopportunitiesService.selectList(null);
    }

    /**
     * 新增商机管理
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Bopportunities bopportunities) {
        bopportunitiesService.insert(bopportunities);
        return SUCCESS_TIP;
    }

    /**
     * 删除商机管理
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer bopportunitiesId) {
        bopportunitiesService.deleteById(bopportunitiesId);
        return SUCCESS_TIP;
    }

    /**
     * 修改商机管理
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Bopportunities bopportunities) {
        bopportunitiesService.updateById(bopportunities);
        return SUCCESS_TIP;
    }

    /**
     * 商机管理详情
     */
    @RequestMapping(value = "/detail/{bopportunitiesId}")
    @ResponseBody
    public Object detail(@PathVariable("bopportunitiesId") Integer bopportunitiesId) {
        return bopportunitiesService.selectById(bopportunitiesId);
    }
}
